<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="USERNAME">
        <el-input
          v-model="queryParams.USERNAME"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生日期" prop="BIRTH">
        <el-input
          v-model="queryParams.BIRTH"
          placeholder="请输入出生日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="GENDER">
        <el-select v-model="queryParams.GENDER" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.yinhe_demo"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="年龄" prop="AGE">
        <el-input
          v-model="queryParams.AGE"
          placeholder="请输入年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="PHONE">
        <el-input
          v-model="queryParams.PHONE"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="籍贯" prop="nativePlace">
        <el-input
          v-model="queryParams.nativePlace"
          placeholder="请输入籍贯"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生地" prop="BIRTHPLACE">
        <el-input
          v-model="queryParams.BIRTHPLACE"
          placeholder="请输入出生地"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="民族" prop="NATION">
        <el-input
          v-model="queryParams.NATION"
          placeholder="请输入民族"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最高学历" prop="highestEducation">
        <el-select v-model="queryParams.highestEducation" placeholder="请选择最高学历" clearable>
          <el-option
            v-for="dict in dict.type.yinhe_demo"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="最高学位" prop="highestDegree">
        <el-select v-model="queryParams.highestDegree" placeholder="请选择最高学位" clearable>
          <el-option
            v-for="dict in dict.type.yinhe_demo"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="毕业学校" prop="graduationSchool">
        <el-input
          v-model="queryParams.graduationSchool"
          placeholder="请输入毕业学校"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业" prop="MAJOR">
        <el-input
          v-model="queryParams.MAJOR"
          placeholder="请输入专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="政治面貌" prop="POLITICS">
        <el-select v-model="queryParams.POLITICS" placeholder="请选择政治面貌" clearable>
          <el-option
            v-for="dict in dict.type.yinhe_demo"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新者" prop="updateBy">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入更新者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备注1" prop="NOTE1">
        <el-input
          v-model="queryParams.NOTE1"
          placeholder="请输入备注1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注2" prop="NOTE2">
        <el-input
          v-model="queryParams.NOTE2"
          placeholder="请输入备注2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注3" prop="NOTE3">
        <el-input
          v-model="queryParams.NOTE3"
          placeholder="请输入备注3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注4" prop="NOTE4">
        <el-input
          v-model="queryParams.NOTE4"
          placeholder="请输入备注4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注5" prop="NOTE5">
        <el-input
          v-model="queryParams.NOTE5"
          placeholder="请输入备注5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注6" prop="NOTE6">
        <el-input
          v-model="queryParams.NOTE6"
          placeholder="请输入备注6"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注7" prop="NOTE7">
        <el-input
          v-model="queryParams.NOTE7"
          placeholder="请输入备注7"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注8" prop="NOTE8">
        <el-input
          v-model="queryParams.NOTE8"
          placeholder="请输入备注8"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注9" prop="NOTE9">
        <el-input
          v-model="queryParams.NOTE9"
          placeholder="请输入备注9"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注10" prop="NOTE10">
        <el-input
          v-model="queryParams.NOTE10"
          placeholder="请输入备注10"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:baseinfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['project:baseinfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['project:baseinfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:baseinfo:export']"
        >导出</el-button>
      </el-col>

        <el-button
          type="warning"
          plain
          icon="el-icon-share"
          size="mini"
          @click="handleInput"
        >生日</el-button>


      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baseinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="ID" />
      <el-table-column label="姓名" align="center" prop="USERNAME" />
      <el-table-column label="出生日期" align="center" prop="BIRTH" />
      <el-table-column label="性别" align="center" prop="GENDER">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yinhe_demo" :value="scope.row.GENDER"/>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="AGE" />
      <el-table-column label="身份证号" align="center" prop="idNumber" />
      <el-table-column label="手机号" align="center" prop="PHONE" />
      <el-table-column label="籍贯" align="center" prop="nativePlace" />
      <el-table-column label="出生地" align="center" prop="BIRTHPLACE" />
      <el-table-column label="民族" align="center" prop="NATION" />
      <el-table-column label="最高学历" align="center" prop="highestEducation">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yinhe_demo" :value="scope.row.highestEducation"/>
        </template>
      </el-table-column>
      <el-table-column label="最高学位" align="center" prop="highestDegree">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yinhe_demo" :value="scope.row.highestDegree"/>
        </template>
      </el-table-column>
      <el-table-column label="毕业学校" align="center" prop="graduationSchool" />
      <el-table-column label="专业" align="center" prop="MAJOR" />
      <el-table-column label="政治面貌" align="center" prop="POLITICS">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yinhe_demo" :value="scope.row.POLITICS"/>
        </template>
      </el-table-column>
      <el-table-column label="简历" align="center" prop="RESUME" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="部门ID" align="center" prop="deptId" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="NOTE" />
      <el-table-column label="备注1" align="center" prop="NOTE1" />
      <el-table-column label="备注2" align="center" prop="NOTE2" />
      <el-table-column label="备注3" align="center" prop="NOTE3" />
      <el-table-column label="备注4" align="center" prop="NOTE4" />
      <el-table-column label="备注5" align="center" prop="NOTE5" />
      <el-table-column label="备注6" align="center" prop="NOTE6" />
      <el-table-column label="备注7" align="center" prop="NOTE7" />
      <el-table-column label="备注8" align="center" prop="NOTE8" />
      <el-table-column label="备注9" align="center" prop="NOTE9" />
      <el-table-column label="备注10" align="center" prop="NOTE10" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['project:baseinfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['project:baseinfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="USERNAME">
          <el-input v-model="form.USERNAME" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="出生日期" prop="BIRTH">
          <el-input v-model="form.BIRTH" placeholder="请输入出生日期" />
        </el-form-item>
        <el-form-item label="性别" prop="GENDER">
          <el-select v-model="form.GENDER" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.yinhe_demo"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="AGE">
          <el-input v-model="form.AGE" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="手机号" prop="PHONE">
          <el-input v-model="form.PHONE" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="籍贯" prop="nativePlace">
          <el-input v-model="form.nativePlace" placeholder="请输入籍贯" />
        </el-form-item>
        <el-form-item label="出生地" prop="BIRTHPLACE">
          <el-input v-model="form.BIRTHPLACE" placeholder="请输入出生地" />
        </el-form-item>
        <el-form-item label="民族" prop="NATION">
          <el-input v-model="form.NATION" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="最高学历" prop="highestEducation">
          <el-select v-model="form.highestEducation" placeholder="请选择最高学历">
            <el-option
              v-for="dict in dict.type.yinhe_demo"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="最高学位" prop="highestDegree">
          <el-select v-model="form.highestDegree" placeholder="请选择最高学位">
            <el-option
              v-for="dict in dict.type.yinhe_demo"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="毕业学校" prop="graduationSchool">
          <el-input v-model="form.graduationSchool" placeholder="请输入毕业学校" />
        </el-form-item>
        <el-form-item label="专业" prop="MAJOR">
          <el-input v-model="form.MAJOR" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="政治面貌" prop="POLITICS">
          <el-select v-model="form.POLITICS" placeholder="请选择政治面貌">
            <el-option
              v-for="dict in dict.type.yinhe_demo"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="简历" prop="RESUME">
          <el-input v-model="form.RESUME" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" />
        </el-form-item>
        <el-form-item label="备注" prop="NOTE">
          <el-input v-model="form.NOTE" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注1" prop="NOTE1">
          <el-input v-model="form.NOTE1" placeholder="请输入备注1" />
        </el-form-item>
        <el-form-item label="备注2" prop="NOTE2">
          <el-input v-model="form.NOTE2" placeholder="请输入备注2" />
        </el-form-item>
        <el-form-item label="备注3" prop="NOTE3">
          <el-input v-model="form.NOTE3" placeholder="请输入备注3" />
        </el-form-item>
        <el-form-item label="备注4" prop="NOTE4">
          <el-input v-model="form.NOTE4" placeholder="请输入备注4" />
        </el-form-item>
        <el-form-item label="备注5" prop="NOTE5">
          <el-input v-model="form.NOTE5" placeholder="请输入备注5" />
        </el-form-item>
        <el-form-item label="备注6" prop="NOTE6">
          <el-input v-model="form.NOTE6" placeholder="请输入备注6" />
        </el-form-item>
        <el-form-item label="备注7" prop="NOTE7">
          <el-input v-model="form.NOTE7" placeholder="请输入备注7" />
        </el-form-item>
        <el-form-item label="备注8" prop="NOTE8">
          <el-input v-model="form.NOTE8" placeholder="请输入备注8" />
        </el-form-item>
        <el-form-item label="备注9" prop="NOTE9">
          <el-input v-model="form.NOTE9" placeholder="请输入备注9" />
        </el-form-item>
        <el-form-item label="备注10" prop="NOTE10">
          <el-input v-model="form.NOTE10" placeholder="请输入备注10" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBaseinfo, getBaseinfo, delBaseinfo, addBaseinfo, updateBaseinfo } from "@/api/project/baseinfo";

export default {
  name: "Baseinfo",
  dicts: ['yinhe_demo'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 基本信息表格数据
      baseinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        USERNAME: null,
        BIRTH: null,
        GENDER: null,
        AGE: null,
        idNumber: null,
        PHONE: null,
        nativePlace: null,
        BIRTHPLACE: null,
        NATION: null,
        highestEducation: null,
        highestDegree: null,
        graduationSchool: null,
        MAJOR: null,
        POLITICS: null,
        RESUME: null,
        userId: null,
        deptId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        NOTE: null,
        NOTE1: null,
        NOTE2: null,
        NOTE3: null,
        NOTE4: null,
        NOTE5: null,
        NOTE6: null,
        NOTE7: null,
        NOTE8: null,
        NOTE9: null,
        NOTE10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询基本信息列表 */
    getList() {
      this.loading = true;
      listBaseinfo(this.queryParams).then(response => {
        this.baseinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ID: null,
        USERNAME: null,
        BIRTH: null,
        GENDER: null,
        AGE: null,
        idNumber: null,
        PHONE: null,
        nativePlace: null,
        BIRTHPLACE: null,
        NATION: null,
        highestEducation: null,
        highestDegree: null,
        graduationSchool: null,
        MAJOR: null,
        POLITICS: null,
        RESUME: null,
        userId: null,
        deptId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        NOTE: null,
        NOTE1: null,
        NOTE2: null,
        NOTE3: null,
        NOTE4: null,
        NOTE5: null,
        NOTE6: null,
        NOTE7: null,
        NOTE8: null,
        NOTE9: null,
        NOTE10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 获取生日按钮操作 */
    handleInput() {
      var shenfenzheng;
      shenfenzheng= this.queryParams.idNumber;
      var year = shenfenzheng.substring(6, 10);// 截取年
      var month = shenfenzheng.substring(10, 12);// 截取月份
      var day = shenfenzheng.substring(12, 14);// 截取天
      this.queryParams.BIRTH=year+'-'+month+'-'+day;


    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.ID)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ID = row.ID || this.ids
      getBaseinfo(ID).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ID != null) {
            updateBaseinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBaseinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const IDs = row.ID || this.ids;
      this.$modal.confirm('是否确认删除基本信息编号为"' + IDs + '"的数据项？').then(function() {
        return delBaseinfo(IDs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('project/baseinfo/export', {
        ...this.queryParams
      }, `baseinfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
